/* GUI CONVERTED from rebkfla.p (converter v1.75) Wed Jan  3 23:00:20 2001 */
/* rebkfla.p - REPETITIVE                                                     */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                         */
/*J2DG*/ /*V8:RunMode=Character,Windows                                       */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 09/27/95   BY: STR *G0Y1*                */
/* REVISION: 7.3      LAST MODIFIED: 05/15/96   BY: *G1VQ* Julie Milligan     */
/* REVISION: 9.0      LAST MODIFIED: 04/16/99   BY: *J2DG* Reetu Kapoor       */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte        */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* REVISION: 9.1      LAST MODIFIED: 12/01/00   BY: *L0P5* Sathish Kumar      */


/*J2DG*/ /* GROUPED MULTIPLE FIELD ASSIGNMENTS INTO ONE AND ADDED NO-UNDO */
/*J2DG*/ /* WHEREVER MISSING AND REPLACED FIND STATEMENTS WITH FOR FIRST  */
/*J2DG*/ /* STATEMENTS FOR ORACLE PERFORMANCE.                            */

/* SUBPROGRAM TO REGISTER A WIP QUANTITY PROCESSED (-INPUT QUE, +OUTPUT QUE)  */

          {mfdeclre.i}

          define input parameter cumwo_lot as character no-undo.
          define input parameter op        as integer   no-undo.
          define input parameter ophist_recid as recid  no-undo.
          define input parameter qty_proc  as decimal   no-undo.

/*N04H**  {rewrsdef.i}                                                        */

          define variable first_op as logical     no-undo.
          define variable glx_mthd like cs_method no-undo.
          define variable glx_set like cs_set     no-undo.
          define variable cur_mthd like cs_method no-undo.
          define variable cur_set like cs_set     no-undo.
          define variable wip_qty as decimal      no-undo.
          define variable prior_op as integer     no-undo.
          define variable lbr_ll_wipval_xfer as decimal no-undo.
          define variable bdn_ll_wipval_xfer as decimal no-undo.
          define variable sub_ll_wipval_xfer as decimal no-undo.
          define variable mtl_ll_wipval_xfer as decimal no-undo.
          define variable lbr_tl_wipval_xfer as decimal no-undo.
          define variable bdn_tl_wipval_xfer as decimal no-undo.
          define variable sub_tl_wipval_xfer as decimal no-undo.
          define variable mtl_tl_wipval_xfer as decimal no-undo.
          define variable this_op_cumproc as decimal    no-undo.


          if qty_proc = 0 then leave.


          /*NO TRANSACTION SHOULD BE PENDING HERE*/
/*G1VQ*          {gprun.i ""gpistran.p"" "(input 1, input """")"} */


/*J2DG**  find wo_mstr where wo_lot = cumwo_lot no-lock. */
/*J2DG*/  for first wo_mstr
/*J2DG*/     fields (wo_lot wo_part wo_site)
/*J2DG*/     where wo_lot = cumwo_lot no-lock:
/*J2DG*/  end.  /* FOR FIRST WO_MSTR */

/*J2DG**  find last wr_route where wr_lot = cumwo_lot and wr_op < op  */
/*J2DG**  no-lock no-error.                                           */
/*J2DG*/  for last wr_route
/*J2DG*/     fields (wr_bdn_act wr_bdn_ll_act wr_bdn_ll_totx wr_bdn_totx
/*J2DG*/             wr_lbr_act wr_lbr_ll_act wr_lbr_ll_totx wr_lbr_totx
/*J2DG*/             wr_lot wr_mtl_act wr_mtl_ll_act wr_mtl_ll_totx
/*J2DG*/             wr_mtl_totx wr_op wr_qty_cumproc wr_qty_inque
/*J2DG*/             wr_qty_outque wr_qty_rejque wr_sub_act wr_sub_ll_act
/*J2DG*/             wr_sub_ll_totx wr_sub_totx)
/*J2DG*/     where wr_lot = cumwo_lot
/*J2DG*/       and wr_op  < op no-lock:
/*J2DG*/  end.  /* FOR LAST WR_ROUTE */

          first_op = yes.

          if available wr_route then do:
/*J2DG*/     assign
                first_op = no
                prior_op = wr_op.
          end.


          /*DETERMINE COSTING METHOD*/
          {gprun.i ""csavg01.p"" "(input wo_part, input wo_site,
          output glx_set, output glx_mthd, output cur_set, output cur_mthd)" }
/*GUI*/ if global-beam-me-up then undo, leave.



          do trans:
/*GUI*/ if global-beam-me-up then undo, leave.

             /*AVERAGE COST HANDLING*/

             if glx_mthd = "AVG" or cur_mthd = "AVG" or cur_mthd = "LAST"
             then do:
                if not first_op then do:
                   find wr_route where wr_lot = cumwo_lot and wr_op = op
                   exclusive-lock.

/*N04H**           {rewrsget.i &lot=wr_lot &op=wr_op}                         */

/*J2DG*/           assign
                      this_op_cumproc = wr_qty_cumproc
                      wip_qty         = wr_qty_inque.

                   find wr_route where wr_lot = cumwo_lot and wr_op = prior_op
                   exclusive-lock.

/*N04H**           {rewrsget.i &lot=wr_lot &op=wr_op}                         */

                   wip_qty = wip_qty + wr_qty_outque + wr_qty_rejque.

                   if qty_proc > 0 then do:
                      if wip_qty <> 0 then do:
/*J2DG*/                 assign
                            lbr_ll_wipval_xfer =
                                 ((wr_lbr_ll_act - wr_lbr_ll_totx) / wip_qty)
                                    * qty_proc

                              bdn_ll_wipval_xfer =
                                 ((wr_bdn_ll_act - wr_bdn_ll_totx) / wip_qty)
                                      * qty_proc

                              sub_ll_wipval_xfer =
                                 ((wr_sub_ll_act - wr_sub_ll_totx) / wip_qty)
                                    * qty_proc

                              mtl_ll_wipval_xfer =
                                 ((wr_mtl_ll_act - wr_mtl_ll_totx) / wip_qty)
                                    * qty_proc

                              lbr_tl_wipval_xfer =
                                 ((wr_lbr_act - wr_lbr_totx) / wip_qty)
                                    * qty_proc

                              bdn_tl_wipval_xfer =
                                 ((wr_bdn_act - wr_bdn_totx) / wip_qty)
                                    * qty_proc

                              sub_tl_wipval_xfer =
                                 ((wr_sub_act - wr_sub_totx) / wip_qty)
                                    * qty_proc

                              mtl_tl_wipval_xfer =
                                 ((wr_mtl_act - wr_mtl_totx) / wip_qty)
                                   * qty_proc.
                        end.
                        else do:
/*J2DG*/                   assign
                              lbr_ll_wipval_xfer = wr_lbr_ll_act - wr_lbr_ll_totx
                              bdn_ll_wipval_xfer = wr_bdn_ll_act - wr_bdn_ll_totx
                              sub_ll_wipval_xfer = wr_sub_ll_act - wr_sub_ll_totx
                              mtl_ll_wipval_xfer = wr_mtl_ll_act - wr_mtl_ll_totx

                              lbr_tl_wipval_xfer = wr_lbr_act - wr_lbr_totx
                              bdn_tl_wipval_xfer = wr_bdn_act - wr_bdn_totx
                              sub_tl_wipval_xfer = wr_sub_act - wr_sub_totx
                              mtl_tl_wipval_xfer = wr_mtl_act - wr_mtl_totx.
                        end.
                     end.
                     else do:
                        if this_op_cumproc <> 0 then do:
/*J2DG*/                   assign
                              lbr_ll_wipval_xfer = (wr_lbr_ll_totx / this_op_cumproc)
                                                      * qty_proc

                              bdn_ll_wipval_xfer = (wr_bdn_ll_totx / this_op_cumproc)
                                                      * qty_proc

                              sub_ll_wipval_xfer = (wr_sub_ll_totx / this_op_cumproc)
                                                      * qty_proc

                              mtl_ll_wipval_xfer = (wr_mtl_ll_totx / this_op_cumproc)
                                                      * qty_proc

                              lbr_tl_wipval_xfer = (wr_lbr_totx / this_op_cumproc)
                                                        * qty_proc

                              bdn_tl_wipval_xfer = (wr_bdn_totx / this_op_cumproc)
                                                      * qty_proc

                              sub_tl_wipval_xfer = (wr_sub_totx / this_op_cumproc)
                                                      * qty_proc

                              mtl_tl_wipval_xfer = (wr_mtl_totx / this_op_cumproc)
                                                      * qty_proc.
                        end.
                        else do:
/*L0P5** BEGIN DELETE SECTION
 * /*J2DG*/                assign
 *                            lbr_ll_wipval_xfer = - wr_lbr_ll_totx
 *                            bdn_ll_wipval_xfer = - wr_bdn_ll_totx
 *                            sub_ll_wipval_xfer = - wr_sub_ll_totx
 *                            mtl_ll_wipval_xfer = - wr_mtl_ll_totx
 *
 *                            lbr_tl_wipval_xfer = - wr_lbr_totx
 *                            bdn_tl_wipval_xfer = - wr_bdn_totx
 *                            sub_tl_wipval_xfer = - wr_sub_totx
 *                            mtl_tl_wipval_xfer = - wr_mtl_totx.
 *
 *L0P5** END DELETE SECTION */

/*L0P5*/                   assign
/*L0P5*/                      lbr_ll_wipval_xfer = 0
/*L0P5*/                      bdn_ll_wipval_xfer = 0
/*L0P5*/                      sub_ll_wipval_xfer = 0
/*L0P5*/                      mtl_ll_wipval_xfer = 0

/*L0P5*/                      lbr_tl_wipval_xfer = 0
/*L0P5*/                      bdn_tl_wipval_xfer = 0
/*L0P5*/                      sub_tl_wipval_xfer = 0
/*L0P5*/                      mtl_tl_wipval_xfer = 0.
                        end.
                     end.

/*G0Y1*/           /* ADD SECTION OF CODE TO MAKE SURE UPDATED TOTX VALUES
                   BETWEEN ZERO AND ACT */
                   {gprun.i ""remaxfer.p""
                   "(input wr_lbr_ll_act, input wr_lbr_ll_totx,
                   input-output lbr_ll_wipval_xfer)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                   {gprun.i ""remaxfer.p""
                   "(input wr_bdn_ll_act, input wr_bdn_ll_totx,
                   input-output bdn_ll_wipval_xfer)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                   {gprun.i ""remaxfer.p""
                   "(input wr_sub_ll_act, input wr_sub_ll_totx,
                   input-output sub_ll_wipval_xfer)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                   {gprun.i ""remaxfer.p""
                   "(input wr_mtl_ll_act, input wr_mtl_ll_totx,
                   input-output mtl_ll_wipval_xfer)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                   {gprun.i ""remaxfer.p""
                   "(input wr_lbr_act, input wr_lbr_totx,
                   input-output lbr_tl_wipval_xfer)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                   {gprun.i ""remaxfer.p""
                   "(input wr_bdn_act, input wr_bdn_totx,
                   input-output bdn_tl_wipval_xfer)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                   {gprun.i ""remaxfer.p""
                   "(input wr_sub_act, input wr_sub_totx,
                   input-output sub_tl_wipval_xfer)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                   {gprun.i ""remaxfer.p""
                   "(input wr_mtl_act, input wr_mtl_totx,
                   input-output mtl_tl_wipval_xfer)"}
/*GUI*/ if global-beam-me-up then undo, leave.

/*G0Y1*/           /* END ADDED SECTION*/

                   find wr_route where wr_lot = cumwo_lot and wr_op = prior_op
                   exclusive-lock.

/*N04H**           {rewrsget.i &lot=wr_lot &op=wr_op}                         */

/*J2DG*/           assign
                   wr_lbr_ll_totx = wr_lbr_ll_totx + lbr_ll_wipval_xfer
                   wr_bdn_ll_totx = wr_bdn_ll_totx + bdn_ll_wipval_xfer
                   wr_sub_ll_totx = wr_sub_ll_totx + sub_ll_wipval_xfer
                   wr_mtl_ll_totx = wr_mtl_ll_totx + mtl_ll_wipval_xfer

                   wr_lbr_totx = wr_lbr_totx + lbr_tl_wipval_xfer
                   wr_bdn_totx = wr_bdn_totx + bdn_tl_wipval_xfer
                   wr_sub_totx = wr_sub_totx + sub_tl_wipval_xfer
                   wr_mtl_totx = wr_mtl_totx + mtl_tl_wipval_xfer.

/*N04H**           {rewrsput.i}                                               */

                   find wr_route where wr_lot = cumwo_lot and wr_op = op
                   exclusive-lock.

/*N04H**           {rewrsget.i &lot=wr_lot &op=wr_op}                         */

/*J2DG*/             assign
                     wr_lbr_ll_act = wr_lbr_ll_act
                     + lbr_ll_wipval_xfer + lbr_tl_wipval_xfer

                     wr_bdn_ll_act = wr_bdn_ll_act
                     + bdn_ll_wipval_xfer + bdn_tl_wipval_xfer

                     wr_sub_ll_act = wr_sub_ll_act
                     + sub_ll_wipval_xfer + sub_tl_wipval_xfer

                     wr_mtl_ll_act = wr_mtl_ll_act
                     + mtl_ll_wipval_xfer + mtl_tl_wipval_xfer.

/*N04H**             {rewrsput.i}                                             */

                end.
             end.


             /*UPDATE QUEUES AND ACCUMS*/
             find wr_route where wr_lot = cumwo_lot and wr_op = op
             exclusive-lock.

/*N04H**     {rewrsget.i &lot=wr_lot &op=wr_op}                               */

/*J2DG*/     assign
                wr_qty_inque   = wr_qty_inque - qty_proc
                wr_qty_outque  = wr_qty_outque + qty_proc
                wr_qty_cumproc = wr_qty_cumproc + qty_proc.


             /*UPDATE OP_HIST*/
             find op_hist where recid(op_hist) = ophist_recid exclusive-lock.
             op_qty_comp = qty_proc.


             /*UPDATE REPETITIVE SCHEDULE*/
             {gprun.i ""reupdsch.p""
             "(input cumwo_lot, input op, input qty_proc)"}
/*GUI*/ if global-beam-me-up then undo, leave.


/*N04H**     {rewrsput.i}                                                     */

          end.
/*GUI*/ if global-beam-me-up then undo, leave.

